/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package au.edu.unsw.bookmarket.util;

import au.edu.unsw.bookmarket.actionform.BookBean;
import au.edu.unsw.bookmarket.actionform.CourseBean;
import au.edu.unsw.bookmarket.actionform.PostAdsBean;
import au.edu.unsw.bookmarket.actionform.SellerBean;
import au.edu.unsw.bookmarket.jdo.Book;
import au.edu.unsw.bookmarket.jdo.Course;
import au.edu.unsw.bookmarket.jdo.Seller;

/**
 *
 * @author gongz
 */
public class BeanMapping {

    public BookBean book2BookBean(Book book) {
        BookBean bookBean = new BookBean();
        try {
            bookBean.setAuthor(book.getAuthor());
            bookBean.setEdition(book.getEdition());
            bookBean.setIsbn(book.getIsbn());
            bookBean.setName(book.getName());
            bookBean.setPublisher(book.getPublisher());
            bookBean.setYear(book.getYear());
            bookBean.setType(book.getType());
            bookBean.setFull_price(book.getFull_price());
            bookBean.setPredefined(book.isPredefined());
        } catch (NullPointerException ne) {
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bookBean;
    }

    public Book bookBean2Book(BookBean bookBean) {
        Book book = new Book();
        try {
            book.setAuthor(bookBean.getAuthor().trim().toLowerCase());
            book.setEdition(bookBean.getEdition());
            book.setIsbn(bookBean.getIsbn().trim().toLowerCase());
            book.setName(bookBean.getName().trim().toLowerCase());
            book.setPublisher(bookBean.getPublisher().trim().toLowerCase());
            book.setYear(bookBean.getYear());
            book.setType(bookBean.getType());
            book.setFull_price(bookBean.getFull_price());
            book.setPredefined(bookBean.isPredefined());
        } catch (NullPointerException ne) {
        } catch (Exception e) {
            e.printStackTrace();
        }
        return book;
    }

    public BookBean postAdsBean2BookBean(PostAdsBean postAdsBean) {
        BookBean bookBean = new BookBean();
        try {
            bookBean.setAuthor(postAdsBean.getBook_author());
            bookBean.setEdition(postAdsBean.getBook_edition());
            bookBean.setIsbn(postAdsBean.getBook_isbn());
            bookBean.setName(postAdsBean.getBook_name());
            bookBean.setPublisher(postAdsBean.getBook_publisher());
            bookBean.setYear(postAdsBean.getBook_year());
            bookBean.setType(postAdsBean.getBook_type());
            bookBean.setFull_price(postAdsBean.getBook_full_price());
            bookBean.setPredefined(false);
        } catch (NullPointerException ne) {
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bookBean;
    }

    public CourseBean course2CourseBean(Course course) {
        CourseBean courseBean = new CourseBean();
        try {
            courseBean.setCode(course.getCode());
            courseBean.setFaculty(course.getFaculty());
            courseBean.setLecturer(course.getLecturer());
            courseBean.setName(course.getName());
            courseBean.setSchool(course.getSchool());
            courseBean.setSession(course.getSession());
            courseBean.setPredefined(course.isPredefined());
        } catch (NullPointerException ne) {
        } catch (Exception e) {
            e.printStackTrace();
        }
        return courseBean;
    }

    public Course courseBean2Course(CourseBean courseBean) {
        Course course = new Course();
        try {
            course.setCode(courseBean.getCode().trim().toLowerCase());
            course.setFaculty(courseBean.getFaculty().trim().toLowerCase());
            course.setLecturer(courseBean.getLecturer().trim().toLowerCase());
            course.setName(courseBean.getName().trim().toLowerCase());
            course.setSchool(courseBean.getSchool().trim().toLowerCase());
            course.setSession(courseBean.getSession().trim().toLowerCase());
            course.setPredefined(courseBean.isPredefined());
        } catch (NullPointerException ne) {
        } catch (Exception e) {
            e.printStackTrace();
        }
        return course;
    }

    public CourseBean postAdsBean2CourseBean(PostAdsBean postAdsBean) {
        CourseBean courseBean = new CourseBean();
        try {
            courseBean.setCode(postAdsBean.getCourse_code());
            courseBean.setFaculty(postAdsBean.getCourse_faculty());
            courseBean.setLecturer(postAdsBean.getCourse_lecturer());
            courseBean.setName(postAdsBean.getCourse_name());
            courseBean.setSchool(postAdsBean.getCourse_school());
            courseBean.setSession(postAdsBean.getCourse_session());
            courseBean.setPredefined(false);
        } catch (NullPointerException ne) {
        } catch (Exception e) {
            e.printStackTrace();
        }
        return courseBean;
    }

    public SellerBean seller2SellerBean(Seller seller) {
        SellerBean sellerBean = new SellerBean();
        try {
            sellerBean.setContact_number(seller.getContact_number());
            sellerBean.setEmail(seller.getEmail());
            sellerBean.setFirst_name(seller.getFirst_name());
            sellerBean.setLast_name(seller.getLast_name());
            sellerBean.setPassword(seller.getPassword());
            sellerBean.setUsername(seller.getUsername());
        } catch (NullPointerException ne) {
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sellerBean;
    }

    public Seller sellerBean2Seller(SellerBean sellerBean) {
        Seller seller = new Seller();
        try {
            seller.setContact_number(sellerBean.getContact_number().trim().toLowerCase());
            seller.setEmail(sellerBean.getEmail().trim().toLowerCase());
            seller.setFirst_name(sellerBean.getFirst_name().trim().toLowerCase());
            seller.setLast_name(sellerBean.getLast_name().trim().toLowerCase());
            seller.setUsername(sellerBean.getUsername().trim().toLowerCase());
            seller.setPassword(sellerBean.getPassword());
        } catch (NullPointerException ne) {
        } catch (Exception e) {
            e.printStackTrace();
        }
        return seller;
    }

    public SellerBean postAdsBean2SellerBean(PostAdsBean postAdsBean) {
        SellerBean sellerBean = new SellerBean();
        try {
            sellerBean.setContact_number(postAdsBean.getSeller_contactnumber());
            sellerBean.setEmail(postAdsBean.getSeller_email());
            sellerBean.setFirst_name(postAdsBean.getSeller_firstname());
            sellerBean.setLast_name(postAdsBean.getSeller_lastname());
            sellerBean.setPassword(postAdsBean.getSeller_password());
            sellerBean.setUsername(postAdsBean.getSeller_username());
        } catch (NullPointerException ne) {
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sellerBean;
    }
}
